package com.origin.niuke.dynamic;

/**
 * 打家劫舍(一)
 * 算法：动态规划
 * dp[i] = Math.max(dp[i - 1], dp[i - 1] + nums[i])
 *
 * @author yezh
 * @date 2023/1/7 15:42
 */
public class NC176 {

    public int rob (int[] nums) {
        // 滚动数组, 由一维数组演变而来
        int a = 0, b = nums[0];
        for (int i = 1; i < nums.length; i++) {
            int tmp = a + nums[i];
            a = b;
            b = Math.max(b, tmp);
        }
        return b;
    }

}
